package com.zh.note.huawei.onehundred.数组组成的最小数字;

/**
 * @Author: zhanghuan
 * @date: 2023/9/2 10:11
 * @description: create it
 */

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;


public class Main {
    public static String solve(String[] strs) {
        Integer MAX = 3;
        List<Integer> myDataList = Arrays.stream(strs).map(item -> Integer.parseInt(item)).sorted()
                .collect(Collectors.toList());
        Integer endIdx = Math.min(MAX, myDataList.size());

        myDataList = myDataList.subList(0, endIdx);


        String values = myDataList.stream().sorted(new Comparator<Integer>() {
                    @Override
                    public int compare(Integer o1, Integer o2) {
                        String left = o1.toString() + o2.toString();
                        String right = o2.toString() + o1.toString();
                        return left.compareTo(right);
                    }
                }).map(item -> String.valueOf(item))
                .collect(Collectors.joining(""));
        return values;
    }

    public static void main(String[] args) {
        try {
            Scanner s = new Scanner(System.in);
            // String s1 = s.nextLine();
            String s1 = "21,30,62,5,31";
            String[] strs = s1.split(",");
            System.out.println(solve(strs));
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("false");
        }
    }
}
